const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    id : 0,
    thisUserID: 0,
    inspectionData : null
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var id = options.id;
    this.data.id = id;
    this.setData({
      id: id,
      thisUserID: app.globalData.loginUserInfo.id
    });
    var that = this;
    wx.request({
      url: app.globalData.domain + "/api/inspection/show/" + id,
      data: {
        token: app.globalData.loginUserInfo.token
      },
      success: function (res) {
        var data = res.data.data        
        wx.setStorageSync( "inspectionData." + id,res.data.data)
        //console.log(data.car_photo);
        //data.car_photo = data.car_photo != "" ? data.car_photo.split(",") : []
        that.setData({
          inspectionData: res.data.data
        });
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  },
  previewImage: function (event){
    if (event.currentTarget.dataset.src){
      var current = event.currentTarget.dataset.index ? event.currentTarget.dataset.index : 0
      var urls = event.currentTarget.dataset.src
      urls = (urls instanceof Array) ? urls : [urls]
      wx.previewImage({
        current: current,
        urls: urls
      });	
      //console.log(event);
    }
  },
  navigateToForm:function(event){
    var id = event.currentTarget.dataset.id
    wx.navigateTo({
      url: '/pages/inspection/form/form?id=' + id,
    })
  }
})